package ciyuan.ChangeMinecraft;

import ciyuan.Block.Machine.Simple.Furnace.SimpleFurnaceContainer;
import ciyuan.Item.ItemRegisterManager;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

/**
 * @author 150149
 */
@Mod.EventBusSubscriber
public class MetalCooling {

    private static final String CY_STONEPOT_COLD = "cystonepotcold";

    @SubscribeEvent
    public static void onInventory(PlayerContainerEvent event) {
        if (event.getContainer() instanceof SimpleFurnaceContainer) {
            return;
        }

        for (Slot slot : event.getContainer().slots) {
            ItemStack itemStack = slot.getItem();

            if (!itemStack.getItem().getDescriptionId().equals(ItemRegisterManager.stonepot1.get().getDescriptionId())) {
                continue;
            }

            CompoundNBT compoundNBT = itemStack.getTag();
            if (compoundNBT == null) {
                compoundNBT = new CompoundNBT();
            }
            if (compoundNBT.contains(CY_STONEPOT_COLD)) {
                long foodTime = compoundNBT.getLong(CY_STONEPOT_COLD);
                if (event.getPlayer().getCommandSenderWorld().getGameTime()-foodTime>10000) {
                    ItemStack itemStack1 = new ItemStack(ItemRegisterManager.metal_block.get());
                    itemStack1.setTag(compoundNBT);
                    slot.set(itemStack1);
                }
            } else {
                compoundNBT.putLong(CY_STONEPOT_COLD,event.getPlayer().getCommandSenderWorld().getGameTime());
            }
            itemStack.setTag(compoundNBT);
        }

    }


}
